473,418 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

how to properly encode ampersands in querystring

I am creating a querystring to look like this:

form_edit.aspx?collectionID=25&confirmationMes sage=New+form+entry+saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMessage' querystring unless I do NOT
encode the ampersand. I assume I'm missing something obvious here. Any
suggestions?

-Darrel
Nov 19 '05 #1
13 26405
Are you looking for Server.URLEncode?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEncode and Server.HTMLDecode?
http://www.devx.com/tips/Tip/13459

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"darrel" <no*****@hotmail.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
I am creating a querystring to look like this:

form_edit.aspx?collectionID=25&amp;confirmationMes sage=New+form+entry+saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMessage' querystring unless I do
NOT
encode the ampersand. I assume I'm missing something obvious here. Any
suggestions?

-Darrel

Nov 19 '05 #2
> Are you looking for Server.URLEncode?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEncode and Server.HTMLDecode?
http://www.devx.com/tips/Tip/13459


Well, I'm 'encoding' it manually, but yea, maybe I need to unencode it.

So, how would I call a querystring in a URL after HTMLDecode?

Or would I decode it, then just parse it as a text string?

-Darrel
Nov 19 '05 #3
You could do that. Or, on the receiving page you can get the value off the
querystring with
code something like this:
Dim nvc As NameValueCollection
nvc=Request.QueryString
Here's more info:

http://msdn.microsoft.com/library/de...ClassTopic.asp

---
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"darrel" <no*****@hotmail.com> wrote in message
news:Oy**************@TK2MSFTNGP15.phx.gbl...
Are you looking for Server.URLEncode?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEncode and Server.HTMLDecode?
http://www.devx.com/tips/Tip/13459


Well, I'm 'encoding' it manually, but yea, maybe I need to unencode it.

So, how would I call a querystring in a URL after HTMLDecode?

Or would I decode it, then just parse it as a text string?

-Darrel

Nov 19 '05 #4
I'm curious why do you need to encode the ampersand? Is it to comply to XHTML
standards?

Cheers,
Tom Pester
I am creating a querystring to look like this:

form_edit.aspx?collectionID=25&amp;confirmationMes sage=New+form+entry+
saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMessage' querystring unless I
do NOT encode the ampersand. I assume I'm missing something obvious
here. Any suggestions?

-Darrel

Nov 19 '05 #5
I suggest that you put one more ampersand after & because each and every
value in a query string is separated by ampersand. For example
index.aspx?a=5&b=10. In your example,
form_edit.aspx?collectionID=25&amp;&confirmationMe ssage=New+....

I hope it helps to encode/decode.

"darrel" wrote:
I am creating a querystring to look like this:

form_edit.aspx?collectionID=25&confirmationMessage =New+form+entry+saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMessage' querystring unless I do NOT
encode the ampersand. I assume I'm missing something obvious here. Any
suggestions?

-Darrel

Nov 19 '05 #6
Kevin Spencer wrote:
The ampersand is a standard URL delimiter for parameters in a query
string. It should never be HTML-Encoded.


Unless it's being included within the HTML itself (for example, in an anchor
tag), in which case it should.

This is valid XHTML (and works just fine):

<a href="http://myserver/mypage.aspx?a=1&amp;b=2">Link</a>

When clicked, the actual URL that will be present in the browser will have a
plain ampersand between the two parameters, not an encoded ampersand.

This is not valid (though it also works):
<a href="http://myserver/mypage.aspx?a=1&b=2">Link</a>

HTML can be a pain in the backside sometimes.

--

(O)enone
Nov 19 '05 #7
> I'm curious why do you need to encode the ampersand? Is it to comply to
XHTML
standards?


I don't *need* too...just trying to get in the habit of doing it.

-Darrel
Nov 19 '05 #8
> I suggest that you put one more ampersand after & because each and every
value in a query string is separated by ampersand. For example
index.aspx?a=5&b=10. In your example,
form_edit.aspx?collectionID=25&amp;&confirmationMe ssage=New+....

I hope it helps to encode/decode.


The problem is that I still have an unencoded ampersand in the URL then.

-Darrel
Nov 19 '05 #9
> The ampersand is a standard URL delimiter for parameters in a query
string.
It should never be HTML-Encoded. If you want to send a literal ampersand,
you should use URL-Encoding, as per my first suggestion.


I was under the impression that an amersand in a URL, unenecoded, was
invalid XHTML.

http://www.456bereastreet.com/archiv...nd_validation/

Also, you introduce the problem of accidently creating an unintentional
entity:

mypage.aspx?id=2&amplitude=4
----

which can mess up some browsers.

-Darrel
Nov 19 '05 #10
This is valid XHTML (and works just fine):

<a href="http://myserver/mypage.aspx?a=1&amp;b=2">Link</a>

When clicked, the actual URL that will be present in the browser will have a plain ampersand between the two parameters, not an encoded ampersand.


Ah! Perhaps that's my problem. I'm not creating an href link, but rather,
I'm using response.redirect

-Darrel
Nov 19 '05 #11
A URL is not HTML or XHTML. It is a URL. I was speaking in the context of a
URL, not the HTML document itself. When a URL is inside an HTML document (in
a link, for example), it needs to be HTML-Encoded. Otherwise not. See
http://www.gbiv.com/protocols/uri/rfc/rfc3986.html

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"darrel" <no*****@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
The ampersand is a standard URL delimiter for parameters in a query

string.
It should never be HTML-Encoded. If you want to send a literal ampersand,
you should use URL-Encoding, as per my first suggestion.


I was under the impression that an amersand in a URL, unenecoded, was
invalid XHTML.

http://www.456bereastreet.com/archiv...nd_validation/

Also, you introduce the problem of accidently creating an unintentional
entity:

mypage.aspx?id=2&amplitude=4
----

which can mess up some browsers.

-Darrel

Nov 19 '05 #12
> a link, for example), it needs to be HTML-Encoded. Otherwise not. See
http://www.gbiv.com/protocols/uri/rfc/rfc3986.html


OH! I think this clarifies things. So, if it's a URL in my codebehind (as a
response.redirect) encoding is rather pointless?

-Darrel
Nov 19 '05 #13
darrel wrote:
Ah! Perhaps that's my problem. I'm not creating an href link, but
rather, I'm using response.redirect


Right, in that case, you don't want to encode ampersands when you're using
them as value separators.

You'd only encode them in a Response.Redirect if they actually formed part
of one of the values, as detailed somewhere else on this thread.

--

(O) e n o n e
Nov 19 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: micha | last post by:
my php script gets delivered text that contains special chars (like german umlauts), and these chars may, may partially or may not be coverted into html entities already. i don't know beforhand. ...
1
by: Travis Pupkin | last post by:
How do you handle an ampersand (&) if it appears as part of the string in a querystring? Is there a way to tell the server it is not the beginning of a new variable being passed, but rather just a...
2
by: SDM | last post by:
I need to create a stylesheet to allow the querystring in my attribute links to format as: <TD<A href='IQNet.asp?f=2&t=3'>Choice 1</A></TD> not <TD<A href='IQNet.asp?f=2&amp;t=3'>Choice...
5
by: AJ Brown | last post by:
How does one allow the use of ampersands (or other special characters for that matter) within Element text and Attribute text? I have problems using LoadXml from a string "<text value="Jack &...
2
by: Larry | last post by:
I am hoping there is a way to encode the querystring part of a URL reached from a hyperlink that will cause the Request to not drop the info after the # in the URL string. Any clues or links to...
3
by: Dariusz Tomon | last post by:
Hi My problem is like that: I'm trying to pass values branza and jezyk in querysting: http://localhost/euroadres/pokazbranza.aspx?branza=transport lotniczy&jezyk=1 Branza is type...
4
by: | last post by:
Hi all, If I am reading this right, then the querystring parameters must be "&amp;" and not "&". However, IIS 6.0 and asp.net request.querystring fails to capture the values if "&amp;" is specified....
3
by: Elroyskimms | last post by:
I have to encode an address which contains an ampersand (&) into a URL with various querystring parameters. The following code works fine: URLString = "www.myserver.com?AD1=" &...
2
by: subbusuresh | last post by:
hi, Any one can help me. <asp:GridView ID="grvDCList" runat="server" AutoGenerateColumns="False" > <Columns> <asp:HyperLinkField HeaderText="DC Number" DataNavigateUrlFields="Code" ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.